/**各个模块的ID及其对应的manuscriptWorkType、manuscriptWorkStatus*/
//去除字符串的空格函数,是去除字符串前后、中间的空格
function trim(str,is_global) 
{ 
   var result; 
       result = str.replace(/(^\s+)|(\s+$)/g,""); 
       if(is_global.toLowerCase()=="g")   
       result = result.replace(/\s/g,""); 
       return result; 
} 
//alert(trim(" 1 2 3 ","g"));
var manuscriptWorkType=null;
var manuscriptWorkStatus=null;
var rolename='';
var value=module.id;//可以判定是进去的哪一个js
function checkModuleId(value){
	switch(value){
	case "receiver-translaterDraw":
		return manuscriptWorkType=1,manuscriptWorkStatus=1,rolename='翻译领稿';
		break;
	case "receiver-checkerDraw":
		return manuscriptWorkType=2,manuscriptWorkStatus=1,rolename='校审领稿';
		break;
	case "receiver-reviserDraw":
		return manuscriptWorkType=3,manuscriptWorkStatus=1,rolename='校对领稿';
		break;
	case "receiver-reviewerDraw":
		return manuscriptWorkType=4,manuscriptWorkStatus=1,rolename='审核领稿';
		break;
	}
}
checkModuleId(value);
var rs_draw = new Ext.data.JsonReader(
{
    root: 'manuscriptWorks',
    totalProperty: 'totalCount'
}, [{
    name: 'urgence',// 紧急程度，取值见urgence常量
    mapping: 'manuscript.urgence',
    hidden: 'true'
}, {
    name: 'securityClassification',// 密级，取值见securityClassification常量
    mapping: 'manuscript.securityClassification',
    hidden: 'true'
},{
	name:'manuscriptWorkId',
	mapping:'manuscriptWorkId',
	hidden:'true'
}, {
    name: 'manuscriptId',// 稿件标识
    mapping: 'manuscript.manuscriptId',
    hidden: 'true'
},{
	name:'principalName',//统稿人
	mapping:'principalName'
}, {
    name: 'title',// 稿件标题
    mapping: 'manuscript.title'
}, {
    name: 'contributeCompanyName',// 稿件公司名字
    mapping: 'manuscript.contributeCompany.contributeCompanyName'
}, {
    name: 'manuscriptCategoryName',// 稿件分类名字
    mapping: 'manuscript.manuscriptCategory.manuscriptCategoryName'
}, {
    name: 'plannedFinishedTime',// 计划完成时间
    mapping: 'plannedFinishedTime'
}]);

var ds_draw = new Ext.data.Store({
	baseParams:{
	manuscriptWorkType:manuscriptWorkType,              //稿件工作类型：1代表翻译人
	manuscriptWorkStatus:manuscriptWorkStatus             //稿件工作状态：1代表分配完成,即已经分发,处于领稿模块中
},
    proxy: new Ext.data.HttpProxy({
        url: 'receiver_ManuscriptWorksForRecipient_list.action',
        method: 'POST'
    }),
    reader: rs_draw
});
var cm_draw = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
    header: "稿件标题",
    width: 100,
    dataIndex: 'title',
    sortable: true,
    renderer: function(value, metadata, record){
        return "<a href = 'javascript:void(0)' onclick=javascript:showdrawView('" +
        record.data.manuscriptId +
        "')> " +
        escapeHTML(value) +
        " </a>";
    }
}, {
    header: "来稿单位",
    width: 120,
    dataIndex: 'contributeCompanyName'

}, {
    header: "稿件分类",
    width: 120,
    dataIndex: 'manuscriptCategoryName'

}, {
    header: "要求完成时间",
    width: 120,
    dataIndex: 'plannedFinishedTime',
    sortable: true,
    renderer: function(value, metadata, record){
		return new Date(value).format('Y-m-d');
    }
}, {
    header: "标识",
    width: 120,
    dataIndex: 'manuscriptId',
    renderer: function(value, metadata, record){
        return tomark(value, metadata, record);
        
    }
},{
	header:"统稿人",
	width:120,
	dataIndex:'principalName'
}, {
    header: "操作",
    width: 120,
    dataIndex: 'manuscriptId',
    renderer: function(value, metadata, record){
	  return "<a href = 'javascript:void(0)' onclick=javascript:draw('" +
      record.data.manuscriptWorkId +
      "')>"+rolename+" </a> <a href='javascript:void(0)' onclick=javascript:refuse('" +
      record.data.manuscriptWorkId +"','"+escapeHTML(trim(record.data.title,"g"))+"','"+record.data.contributeCompanyName+"')>拒绝</a>";
    }
}]);

// 时间操作START
function totime(value, metadata, record){
    return new Date(value).format('Y-m-d H:i');
}

// 时间操作END
// 来稿START
function toisBoss(value){
    if (value == userId) {
        return true;
    }
    else {
        return false;
    }
}

function tourgence(value){

    switch (value) {
        case 0:
            return "普通";
            break;
        case 5:
            return "紧急";
            break;
        case 10:
            return "特急";
            break;
    }
    
}

function tosecurityClassification(value){

    switch (value) {
        case 1:
            return "普通";
            break;
        case 2:
            return "秘密";
            break;
        case 3:
            return "机密";
            break;
        case 5:
            return "绝密";
            break;
    }
    
}

function tolanguage(value){

    switch (value) {
        case 1:
            return "汉语";
            break;
        case 2:
            return "藏语";
            break;
    }
    
}

function totargetLanguage(value){

    switch (value) {
        case 1:
            return "汉语";
            break;
        case 2:
            return "藏语";
            break;
    }
    
}

function totexttype(value){

    switch (value) {
        case 0:
            return "纸质稿件";
            break;
        case 0x0100:
            return "电子稿件";
            break;
    }
    
}

function totype(value) {
	if(value=="DW"){
		return "党委";
	}else if(value=="RD"){
		return "人大";
	}else if(value=="ZF"){
		return "政府";
	}else if(value=="ZX"){
		return "政协";
	}else if(value=="QT"){
		return "其他";
	}else{
		return value;
	}
}

function toisAll(value){
    var fag = 0;
    for (var i = 0; i < value.length; i++) {
        if (value[i].status == 5) {
            fag++;
        }
    };
    if (fag == value.length) {
        return true;
    }
    else {
        return false;
    }
}

function toisElectronic(value){
    switch (value) {
        case 0:
            return false;
            break;
        case 0x0100:
            return true;
            break;
    }
    
}

// 来稿END
// 表单START
var urgence;
var securityClassification;
var language;
var targetLanguage;
var contributeTime;
var plannedConsummationTime;
var type;
var texttype;
var isAll = true;
var isElectronic = true;
function formchange(respText){
	isElectronic = toisElectronic(respText.manuscript.type);
	urgence = tourgence(respText.manuscript.urgence);
	securityClassification = tosecurityClassification(respText.manuscript.securityClassification);
	language = tolanguage(respText.manuscript.language);
	targetLanguage = totargetLanguage(respText.manuscript.targetLanguage);
	contributeTime = totime(respText.manuscript.contributeTime, "", "");
	plannedConsummationTime = totime(
			respText.manuscript.plannedConsummationTime, "", "");
	texttype = totexttype(respText.manuscript.type);
	type = totype(respText.manuscript.contributeCompany.type);
}

// 表单END
// 标志START
var re;
function tomark(value, metadata, record) {
    var title = '&nbsp;密级&nbsp;&nbsp;&nbsp;&nbsp;紧急程度&nbsp;';
    var tip;
    var s1 = "&nbsp;普通&nbsp;&nbsp;&nbsp;&nbsp;";
    var s2 = "&nbsp;秘密&nbsp;&nbsp;&nbsp;&nbsp;";
    var s3 = "&nbsp;机密&nbsp;&nbsp;&nbsp;&nbsp;";
    var s5 = "&nbsp;绝密&nbsp;&nbsp;&nbsp;&nbsp;";
    var u0 = "&nbsp;&nbsp;&nbsp;普通&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    var u5 = "&nbsp;&nbsp;&nbsp;紧急&nbsp;&nbsp;&nbsp;&nbsp;";
    var u10 = "&nbsp;&nbsp;&nbsp;特急";
    var c0 = "&nbsp<img src='images/clock_blue.gif'  />&nbsp";// 普通urgence
    var c5 = "&nbsp<img src='images/clock_green.gif' />&nbsp";// 紧急
    var c10 = "&nbsp<img src='images/clock_red.gif' />&nbsp";// 特急
    var l1 = "&nbsp<img src='images/lock_blue.gif'  />&nbsp";// 普通securityClassification
    var l2 = "&nbsp<img src='images/lock_gold.gif'/>&nbsp"; // 秘密
    var l3 = "&nbsp<img src='images/lock_green.gif' />&nbsp";// 机密
    var l5 = "&nbsp<img src='images/lock_red.gif'  />&nbsp";// 绝密
    switch (record.data.securityClassification) {
        case 1:
            switch (record.data.urgence) {
                case 0:
                	re = l1 + c0;
                    tip = s1 + u0;
                    break;
                case 5:
                	re = l1 + c5 ;
                    tip = s1 + u5;
                    break;
                case 10:
                	re = l1 + c10;
                    tip = s1 + u10;
                    break;
            }
            break;
        case 2:
            switch (record.data.urgence) {
                case 0:
                	re = l2 + c0;
                    tip = s2 + u0;
                    break;
                case 5:
                	re = l2 + c5;
                    tip = s2 + u5;
                    break;
                case 10:
                	re = l2 + c10;
                    tip = s2 + u10;
                    break;
            }
            break;
        case 3:
            switch (record.data.urgence) {
	            case 0:
	            	re = l3 + c0;
	                tip = s3 + u0;
	                break;
	            case 5:
	            	re = l3 + c5;
	                tip = s3 + u5;
	                break;
	            case 10:
	            	re = l3 + c10;
	                tip = s3 + u10;
	                break;
            }
            
            break;
        case 5:
            switch (record.data.urgence) {
	            case 0:
	            	re = l5 + c0;
	                tip = s5 + u0;
	                break;
	            case 5:
	            	re = l5 + c5;
	                tip = s5 + u5;
	                break;
	            case 10:
	            	re = l5 + c10;
	                tip = s5 + u10;
	                break;
	            }
            break;
    }
    metadata.attr = 'ext:qtitle="' + title + '"' + ' ext:qtip="' + tip + '"';
    return re;
}
// 标志END

// 查看稿件
window.showdrawView = function(needParam){
    Ext.Ajax.request({
        url: 'receiver_manuscriptInfo_view.action',
        method: 'post',
        params: {
            manuscriptId: needParam
        },
        success: function(resp, opts){
            var respText = Ext.util.JSON.decode(resp.responseText);
            if (respText.success) {
				formchange(respText);
				var mywindow = new Ext.Window({
					title : '稿件详情',
					width : 600,
					constrainHeader:true, 
					resizable : false,
					autoHeight : true,
					modal : true,
					closable:false,
					iconCls:'manuscript',
					closeAction : 'hide',
					items : [new Ext.FormPanel({
						border : false,
						labelAlign : 'right',
						plain:true,
						labelWidth : 100,
						frame : true,
						items : [{
							fieldLabel : '稿件标题',
							xtype : 'textfield',
							readOnly : true,
							value : respText.manuscript.title,
							anchor : '93%',
							itemCls:'unedit'
						},{
							autoHeight : true,
							xtype : 'textfield',
							fieldLabel : '稿件编号',
							readOnly : true,
							value : respText.manuscript.manuscriptCode,
							itemCls:'form_text unedit'
						},{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '来稿单位',
										readOnly : true,
										value : respText.manuscript.contributeCompany.contributeCompanyName,
										itemCls:'form_text unedit'
									},{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '来稿单位类型',
										readOnly : true,
										value : respText.manuscript.contributeCompany.type,
										itemCls:'form_text unedit'
									},{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '联系人',
										readOnly : true,
										value : respText.manuscript.contributeCompanyPerson.name,
										itemCls:'form_text unedit'
									},{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '稿件编号',
										readOnly : true,
										value : respText.manuscript.manuscriptCode,
										itemCls:'form_text unedit'
									},{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '联系人手机',
										readOnly : true,
										value : respText.manuscript.contributeCompanyPerson.mobilePhone,
										itemCls:'form_text unedit'
									},{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '联系人邮箱',
										readOnly : true,
										value : respText.manuscript.contributeCompanyPerson.email,
										itemCls:'form_text unedit'
									},{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '稿件分类',
										readOnly : true,
										value : respText.manuscript.manuscriptCategory.manuscriptCategoryName,
										itemCls:'form_text unedit'
									},{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '紧急程度',
										readOnly : true,
										value : urgence,
										itemCls:'form_text unedit'
									},{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '文档类型',
										readOnly : true,
										value : texttype,
										itemCls:'form_text unedit'
									},{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '原稿文种',
										readOnly : true,
										value : language,
										itemCls:'form_text unedit'
									},{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '密级',
										readOnly : true,
										value : securityClassification,
										itemCls:'form_text unedit'
									},{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '目标语言',
										readOnly : true,
										value : targetLanguage,
										itemCls:'form_text unedit'
									},{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '字数',
										readOnly : true,
										value : respText.manuscript.wordNum,
										itemCls:'form_text unedit'

									},
									{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '来稿时间',
										readOnly : true,
										value : contributeTime,
										itemCls:'form_text unedit'
									},{
										autoHeight : true,
										xtype : 'textfield',
										fieldLabel : '计划完成时间',
										readOnly : true,
										value : plannedConsummationTime,
										itemCls:'form_text unedit'
						            },{
						            	fieldLabel : '备注',
						            	xtype: 'panel',
			                            width: 425,
			                            itemCls: 'clear',
										html: changeRemark(respText)
						            } ],
						    buttons:[{
						    	text:'关闭',
						    	handler:function(){
						    	mywindow.close();
						    }
						    }]      
					})
				]
				}).show();
			}
            else {
                Ext.Msg.alert('查看详情失败');
            }
        },
        failure: function(){
            Ext.Msg.show({
                title: '错误提示',
                msg: '修改失败!',
                buttons: Ext.Msg.OK,
                icon: Ext.Msg.ERROR,
                width: 200
            });
        }
    });
};

function changeRemark(respText){
	return "<div align=\"center\"><a href='javascript:void(0)'  onclick=javascript:showRemark('" + respText.manuscript.manuscriptId + "')>备注详情</a></div>";
}

window.showRemark = function(v){
    Ext.Ajax.request({
        url: 'receiver_manuscriptInfo_view.action',
        method: 'post',
        params: {
            manuscriptId: v
        },
        success: function(resp, opts){
            var respText = Ext.util.JSON.decode(resp.responseText);
            if (respText.success) {
                var window_remark = new Ext.Window({
                    title: '备注详情',
                    closable: false,
                    width: 600,
                    resizable: false,
                    height: 400,
                    iconCls: 'manuscript',
                    modal: true,
                    constrain: true,
                    closeAction: 'close',
                    layout: 'fit',
                    items: [{
                        xtype: 'htmleditor',
                        enableAlignments: false,
                        enableColors: false,
                        enableFont: false,
                        enableFontSize: false,
                        enableFormat: false,
                        enableLinks: false,
                        enableLists: false,
                        enableSourceEdit: false,
                        readOnly: true,
                        value: respText.manuscript.remark
                    }],
                    buttons: [{
                        text: '关闭',
                        handler: function(){
                            window_remark.close();
                        }
                    }]
                
                
                }).show();
            }
        },
        failure: function(){
            Ext.Msg.show({
                title: '错误提示',
                msg: '查看失败!',
                buttons: Ext.Msg.OK,
                icon: Ext.Msg.ERROR,
                width: 200
            });
        }
    })
}


/** 查看稿件END*/

// 领稿操作START
window.draw = function(needParam){
	Ext.MessageBox.confirm(rolename,'请确认翻译人领取翻译稿！',callback);
	function callback(id){
		if(id=='yes'){
			Ext.Ajax.request({
				url:'receiver_principalGetManuscript_accept.action',
				method:'post',
				params:{manuscriptWorkId:needParam},
			    success: function(resp,opts){
					var respText=Ext.util.JSON.decode(resp.responseText);
					if(respText.success){
						ds_draw.reload();
                            Ext.Msg.show({
                            title: '成功提示',
                            msg: '领稿成功!',
                            icon : Ext.Msg.INFO,
                            buttons: Ext.Msg.OK,
                            width: 200
                            });
					}else{
                             Ext.Msg.show({
                             title: '错误提示',
                             msg:respText.errorMessage,
                             buttons: Ext.Msg.OK,
                             icon: Ext.Msg.ERROR,
                             width: 200
                             });
					}
                   }
			});
		}
	}
};

// 拒绝操作START
window.refuse = function(manuscriptWorkId,title,contributeCompanyName){
	  var window_draw = new Ext.Window({
                    title: '拒绝领稿',
                    width : 600,
					resizable : false,
					autoHeight : true,
					modal : true,
					closeAction : 'hide',
                    items: [
                        refuseForm= new Ext.form.FormPanel({
                        border : false,
						labelAlign : 'right',
						plain:true,
						labelWidth : 100,
						frame : true,
                        items: [{
                            fieldLabel: '稿件标题',
                            xtype: 'textfield',
							readOnly : true,
                            value: title,
							anchor : '95%',
							itemCls : "unedit"
                        }, {
                            autoHeight : true,
							xtype : 'textfield',
							fieldLabel : '来稿单位',
							readOnly : true,
							value : contributeCompanyName,
							itemCls:'form_text unedit'
                        },{
                        	id: 'rema',
                        	store :new Ext.data.SimpleStore ({
                        		data:[['开会'],['出差'],['休假'],['任务冲突'],['其他']],
                        		fields:['value']
                        	}),
                        	displayField:'value',
                        	valueField:'value',
                        	hiddenName:'remark',
                        	mode:'local',
                        	fieldLabel:'拒绝理由',
                        	triggerAction : 'all',
                        	allowBlank:false,
                        	editable :false,
                        	emptyText :'请选择',
                        	xtype:'combo',
                        	itemCls : 'form_text',
                        	listeners:{
                        		"select":function(obj){
                        			var cmpInputRemake=Ext.getCmp('inputrema');
                        			if(obj.value=="其他"){
                        				cmpInputRemake.setDisabled(false);
                        				cmpInputRemake.setVisible(true);
                        			}else{
                        				cmpInputRemake.setValue('');
                        				cmpInputRemake.setDisabled(true);
                        				obj.show();
                        				cmpInputRemake.setVisible(false);
                        			}
                        		}
                        	} 
                        }, {
                        	id:'inputrema',
                            xtype: 'textarea',
                            allowBlank:false,
                            hidden:true,
                            maxLength:200, 
                            maxLengthText:'超过了最大字符数200' ,
							anchor : '95%',
							itemCls:'clear'
                        }]
                    })],
                    buttons: [{
                        text: '拒绝',
                        type:'submit',
                        handler: function(){
                    	if(refuseForm.form.isValid()){
                    		var remark="";
                        	if(Ext.getCmp("inputrema").isVisible()){
                        		remark=Ext.getCmp("inputrema").getValue();
                        	}else{
                        		remark=Ext.getCmp("rema").getValue();
                        	}
                        	Ext.Ajax.request({
                        		url: 'receiver_principalRejectManuscriptWork_reject.action',
            					method: 'post',
            					params :{
            						manuscriptWorkId:manuscriptWorkId,
            						remark:remark
            					},
            					success: function(){
            					    window_draw.close();
            					    ds_draw.reload();
            					    Ext.Msg.show({
            					    	title : '操作提示',
										msg : '拒绝成功!',
										buttons : Ext.Msg.OK,
										icon : Ext.Msg.INFO,
										width : 200
            					    });
            					},  
            					failure:function(){
            						Ext.Msg.show({
             					    	title : '操作提示',
											msg : '拒绝失败!',
											buttons : Ext.Msg.OK,
											icon: Ext.Msg.ERROR,
											width : 200
             					    });
            					}
                        	});
//                    		refuseForm.form.doAction(
//                    				'submit',{
//                    					url: 'receiver_principalRejectManuscriptWork_reject.action',
//                    					method: 'post',
//                    					params :{
//                    						manuscriptWorkId:manuscriptWorkId,
//                    						remark:remark
//                    					},
//                    					success: function(form,action){
//                    					    window_draw.close();
//                    					    ds_draw.reload();
//                    					    Ext.Msg.show({
//                    					    	title : '操作提示',
//    											msg : '拒绝成功!',
//    											buttons : Ext.Msg.OK,
//    											icon : Ext.Msg.INFO,
//    											width : 200
//                    					    });
//                    					},
//                    				    failure:function(form,action){
//                    						Ext.Msg.show({
//                     					    	title : '操作提示',
//     											msg : '交稿失败!',
//     											buttons : Ext.Msg.OK,
//     											icon: Ext.Msg.ERROR,
//     											width : 200
//                     					    });
//                    					}
//                    				}
//                    		);
                    	}
                        }
                    }, {
                        text: '取消',
                        handler: function(){
                            window_draw.close();
                        }
                    }]
                
                }).show();
}
// 拒绝操作END
var grid_draw = new Ext.grid.GridPanel({
    title: rolename,
    loadMask: {
        msg: '数据加载中...'
    },
    ds: ds_draw,
    store: ds_draw,
    region: 'center',
    autoScroll: true,
    cm: cm_draw,
    autoExpandColumn: 1,
    bbar: new Ext.PagingToolbar({
        pageSize: 20,
        store: ds_draw,
        displayInfo: true,
        beforePageText: '第',
        afterPageText: '页-共{0}页',
        displayMsg: '显示{0} - {1} 条  共 {2} 条',
        emptyMsg: "没有记录"
    })
});
ds_draw.load({
    params: {
        start: 0,
        limit: 20
    }
});
var p_draw = {
    id: module.id,
    border: false,
    layout: 'border',
    items: [grid_draw]
};
Ext.getCmp('content-panel').add(p_draw);
Ext.getCmp('content-panel').layout.setActiveItem(module.id);
Ext.getCmp('content-panel').uxmodules="undefined";
